/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Penjualan;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import java.util.logging.*;

/**
 *
 * @author IDIFIDI
 */
public class editPenjualanForm extends JDialog
{
    private JLabel inputLabel;
    private JTextField inputText;
    private JButton cariButton;
    private FormPenjualan form;

    public editPenjualanForm()
    {
        this.setTitle("Edit Data Penjualan");
        this.setSize(330,75);
        this.setLocation(500,300);
        this.setLayout(new FlowLayout());
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

        inputLabel=new JLabel("Input Nomor Penjualan : ");
        inputText=new JTextField("MAFYJ-",8);
        cariButton=new JButton("Cari");

        this.add(inputLabel);
        this.add(inputText);
        this.add(cariButton);

        cariButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    cariAction();
                } catch (Exception ex) {
                    Logger.getLogger(editPenjualanForm.class.getName()).log(Level.SEVERE, null, ex);
                }
                setVisible(false);
            }
        });
    }

    public void cariAction() throws Exception
    {
//        FormPenjualan form=new FormPenjualan();
        Penjualan jual=new Penjualan();
        String kode=inputText.getText();
//        String notrans = jual.getNoPenjualan();
        System.out.println(kode);
        jual.setNoPenjualan(kode);
        
        if(inputText.getText().equalsIgnoreCase("MAFYJ-"))
        {
            JOptionPane.showMessageDialog(null, "Masukkan nomor penjualan yang akan dicari");
        }
        else
        {
            try {
                jual = PenjualanController.getKoneksi().cariNomor(jual);
                String noHp=jual.getNoHp();
                String prov=jual.getProvider();
                int nom=jual.getNominal();
                int harga=jual.getHarga();

//                form.noJualText.setText(notrans);
                getForm().noJualText.setText(kode);
                getForm().noJualText.setEditable(false);
                getForm().nomorHpText.setText(noHp);
                getForm().providerCombo.setSelectedItem(prov);
                getForm().nominalText.setText(String.valueOf(nom));
                getForm().hargaText.setText(String.valueOf(harga));

//                JOptionPane.showMessageDialog(null, ""+notrans);


                JOptionPane.showMessageDialog(null, "Kode " + kode + " berhasi ditemukan!");
                this.setVisible(false);
            } catch (SQLException ex) {
            Logger.getLogger(editPenjualanForm.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, "Kode " + kode + " tidak ditemukan!");
            } catch (FileNotFoundException ex) {
                Logger.getLogger(FormPenjualan.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(null, "Kode " + kode + " tidak ditemukan!");
            } catch (IOException ex) {
                Logger.getLogger(FormPenjualan.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(null, "Kode " + kode + " tidak ditemukan!");
            }
        }
//        editPenjualanForm edit=new editPenjualanForm();
//        edit.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    }

    /**
     * @return the form
     */
    public FormPenjualan getForm() {
        return form;
    }

    /**
     * @param form the form to set
     */
    public void setForm(FormPenjualan form) {
        this.form = form;
    }
}